package com.smartwebx.ha.web.admin.module.screen.report;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.dataresolver.Param;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.smartwebx.ha.biz.assign.HaDirectoryManager;
import com.smartwebx.ha.biz.assign.HaReportManager;
import com.smartwebx.ha.dal.assign.bean.HaDirectory;
import com.smartwebx.ha.web.admin.common.HaUserSys;

/**
 * 
 * 创建人：Dream~天涯 
 * 创建时间：2015-4-27 下午9:35:48
 * 邮箱：154494796@qq.com
 * 备注：
 */
public class AjaxReportToAreaData {
	@Autowired
	private HttpServletResponse response;
	@Autowired
	private HaReportManager haReportManager;
	@Autowired
	private HaDirectoryManager haDirectoryManager;
	@Autowired
	private HttpSession session;
	public void execute(@Param("driectorId") String driectorId, @Param("type") String type) throws Exception{
		HaUserSys user=(HaUserSys) session.getAttribute("haUser");
		response.setContentType("application/json");
		PrintWriter out=response.getWriter();
		ObjectMapper mapper=new ObjectMapper();
		if("1".equals(type)){
			List<HaDirectory> haDirectory = haDirectoryManager.getDirectoryData("reportId", Integer.parseInt(driectorId), 1);
			if (haDirectory.size()==0) {
				
			}else{
				driectorId = haDirectory.get(0).getId().toString();
			}
		}
		mapper.writeValue(out, haReportManager.getUserTree(user.getUserId(),1,driectorId));

	}
}
